from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-02 14:02:13.635090
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 02, May, 2022
Time: 14:02:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.1447
Nobs: 644.000 HQIC: -49.5268
Log likelihood: 7891.47 FPE: 2.42989e-22
AIC: -49.7690 Det(Omega_mle): 2.11524e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.325718 0.061711 5.278 0.000
L1.Burgenland 0.105070 0.039284 2.675 0.007
L1.Kärnten -0.110216 0.020599 -5.350 0.000
L1.Niederösterreich 0.196316 0.082030 2.393 0.017
L1.Oberösterreich 0.118598 0.081006 1.464 0.143
L1.Salzburg 0.258527 0.041753 6.192 0.000
L1.Steiermark 0.043862 0.054884 0.799 0.424
L1.Tirol 0.105189 0.044302 2.374 0.018
L1.Vorarlberg -0.063623 0.039139 -1.626 0.104
L1.Wien 0.026489 0.071750 0.369 0.712
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052579 0.131912 0.399 0.690
L1.Burgenland -0.032839 0.083973 -0.391 0.696
L1.Kärnten 0.040200 0.044033 0.913 0.361
L1.Niederösterreich -0.189708 0.175347 -1.082 0.279
L1.Oberösterreich 0.448057 0.173159 2.588 0.010
L1.Salzburg 0.285573 0.089251 3.200 0.001
L1.Steiermark 0.105985 0.117319 0.903 0.366
L1.Tirol 0.313769 0.094699 3.313 0.001
L1.Vorarlberg 0.021862 0.083664 0.261 0.794
L1.Wien -0.037023 0.153372 -0.241 0.809
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190658 0.031624 6.029 0.000
L1.Burgenland 0.090173 0.020131 4.479 0.000
L1.Kärnten -0.008006 0.010556 -0.758 0.448
L1.Niederösterreich 0.249115 0.042037 5.926 0.000
L1.Oberösterreich 0.157332 0.041512 3.790 0.000
L1.Salzburg 0.040447 0.021397 1.890 0.059
L1.Steiermark 0.024828 0.028126 0.883 0.377
L1.Tirol 0.086933 0.022703 3.829 0.000
L1.Vorarlberg 0.053933 0.020057 2.689 0.007
L1.Wien 0.116114 0.036769 3.158 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112382 0.031765 3.538 0.000
L1.Burgenland 0.045494 0.020221 2.250 0.024
L1.Kärnten -0.014349 0.010603 -1.353 0.176
L1.Niederösterreich 0.180497 0.042224 4.275 0.000
L1.Oberösterreich 0.327249 0.041697 7.848 0.000
L1.Salzburg 0.101590 0.021492 4.727 0.000
L1.Steiermark 0.110388 0.028251 3.907 0.000
L1.Tirol 0.097968 0.022804 4.296 0.000
L1.Vorarlberg 0.059349 0.020146 2.946 0.003
L1.Wien -0.021320 0.036932 -0.577 0.564
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115823 0.059138 1.959 0.050
L1.Burgenland -0.043289 0.037646 -1.150 0.250
L1.Kärnten -0.046324 0.019740 -2.347 0.019
L1.Niederösterreich 0.144907 0.078610 1.843 0.065
L1.Oberösterreich 0.157082 0.077629 2.024 0.043
L1.Salzburg 0.283745 0.040012 7.091 0.000
L1.Steiermark 0.055595 0.052595 1.057 0.291
L1.Tirol 0.165570 0.042455 3.900 0.000
L1.Vorarlberg 0.096225 0.037507 2.565 0.010
L1.Wien 0.073004 0.068758 1.062 0.288
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059979 0.046554 1.288 0.198
L1.Burgenland 0.030419 0.029636 1.026 0.305
L1.Kärnten 0.051509 0.015540 3.315 0.001
L1.Niederösterreich 0.206232 0.061883 3.333 0.001
L1.Oberösterreich 0.322774 0.061110 5.282 0.000
L1.Salzburg 0.038232 0.031498 1.214 0.225
L1.Steiermark 0.007022 0.041404 0.170 0.865
L1.Tirol 0.130421 0.033421 3.902 0.000
L1.Vorarlberg 0.063888 0.029526 2.164 0.030
L1.Wien 0.090389 0.054128 1.670 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172510 0.055927 3.085 0.002
L1.Burgenland 0.005972 0.035602 0.168 0.867
L1.Kärnten -0.065285 0.018669 -3.497 0.000
L1.Niederösterreich -0.098224 0.074341 -1.321 0.186
L1.Oberösterreich 0.204511 0.073414 2.786 0.005
L1.Salzburg 0.054853 0.037840 1.450 0.147
L1.Steiermark 0.240295 0.049740 4.831 0.000
L1.Tirol 0.501630 0.040149 12.494 0.000
L1.Vorarlberg 0.060964 0.035471 1.719 0.086
L1.Wien -0.074893 0.065025 -1.152 0.249
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148215 0.061996 2.391 0.017
L1.Burgenland 0.004793 0.039465 0.121 0.903
L1.Kärnten 0.060304 0.020695 2.914 0.004
L1.Niederösterreich 0.184513 0.082409 2.239 0.025
L1.Oberösterreich -0.062348 0.081380 -0.766 0.444
L1.Salzburg 0.208135 0.041946 4.962 0.000
L1.Steiermark 0.134130 0.055137 2.433 0.015
L1.Tirol 0.068541 0.044506 1.540 0.124
L1.Vorarlberg 0.144708 0.039320 3.680 0.000
L1.Wien 0.110976 0.072081 1.540 0.124
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.378100 0.036493 10.361 0.000
L1.Burgenland -0.001108 0.023231 -0.048 0.962
L1.Kärnten -0.021794 0.012182 -1.789 0.074
L1.Niederösterreich 0.211544 0.048509 4.361 0.000
L1.Oberösterreich 0.226050 0.047904 4.719 0.000
L1.Salzburg 0.038812 0.024691 1.572 0.116
L1.Steiermark -0.014007 0.032456 -0.432 0.666
L1.Tirol 0.095105 0.026198 3.630 0.000
L1.Vorarlberg 0.052972 0.023145 2.289 0.022
L1.Wien 0.036504 0.042430 0.860 0.390
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036127 0.113603 0.173315 0.140781 0.102519 0.085422 0.037656 0.209906
Kärnten 0.036127 1.000000 -0.021283 0.134327 0.052527 0.090142 0.442093 -0.060582 0.092470
Niederösterreich 0.113603 -0.021283 1.000000 0.322744 0.130601 0.283674 0.075087 0.162693 0.296133
Oberösterreich 0.173315 0.134327 0.322744 1.000000 0.221969 0.310109 0.169101 0.150171 0.249675
Salzburg 0.140781 0.052527 0.130601 0.221969 1.000000 0.132075 0.097115 0.112984 0.129872
Steiermark 0.102519 0.090142 0.283674 0.310109 0.132075 1.000000 0.139986 0.120948 0.049240
Tirol 0.085422 0.442093 0.075087 0.169101 0.097115 0.139986 1.000000 0.069399 0.149452
Vorarlberg 0.037656 -0.060582 0.162693 0.150171 0.112984 0.120948 0.069399 1.000000 0.006622
Wien 0.209906 0.092470 0.296133 0.249675 0.129872 0.049240 0.149452 0.006622 1.000000